package com.liyujie.splitscreen.ui;

import android.app.Presentation;
import android.content.Context;
import android.os.Bundle;
import android.view.Display;
import android.view.WindowManager;

import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;

public abstract class BasePresentation<V extends ViewDataBinding> extends Presentation {
    protected Context mContext;
    protected V binding;


    public BasePresentation(Context outerContext, Display display) {
        super(outerContext, display);

    }

    public BasePresentation(Context outerContext, Display display, int theme) {
        super(outerContext, display, theme);

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //保持亮屏
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        //创建
        initCreate();
        //页面接受的参数方法
        initParam();
        //页面数据初始化方法
        //私有的初始化Databinding和ViewModel方法
        initViewDataBinding(savedInstanceState);
        //
        initView();
        //
        initData();
        //页面事件监听的方法，一般用于ViewModel层转到View层的事件注册
        initViewObservable();
    }


    public void initCreate(){

    }


    public void initParam() {

    }

    /**
     * 初始化根布局
     *
     * @return 布局layout的id
     */
    public abstract int initContentView(Bundle savedInstanceState);

    /**
     * 注入绑定
     */
    private void initViewDataBinding(Bundle savedInstanceState) {
        binding = DataBindingUtil.setContentView(getOwnerActivity(), initContentView(savedInstanceState));
    }

    public void initView() {

    }

    public void initData() {

    }

    public void initViewObservable() {

    }
}
